package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import com.zcx.helper.http.note.HttpNew;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/8.
 */
@HttpInlet(Conn.INLET_API_MYORDER_MYORDER)
public class GetApiMyOrder extends BaseAsyGet<GetApiMyOrder.Info> {
    public String type, uid, starttime, endtime;

    public GetApiMyOrder(AsyCallBack<GetApiMyOrder.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            JSONObject o = jsonObject.optJSONObject("data");
            Info info = new Info();
            Data d = new Data();

            JSONArray array = o.optJSONArray("bcorder");

            if (array != null) {
                for (int i = 0; i < array.length(); i++) {

                    JSONObject object = array.optJSONObject(i);

                    Business business = new Business();
                    business.id = object.optString("id");
                    business.posttime = object.optString("posttime");
                    business.total = object.optString("total");
                    business.pstate = object.optString("pstate");
                    business.title = object.optString("title");
                    business.type = object.optString("type");
                    business.ordersn = object.optString("ordersn");

                    d.businessList.add(business);
                }
            }

            JSONArray array3 = o.optJSONArray("alorder");
            if (array3 != null) {
                for (int i = 0; i < array3.length(); i++) {

                    JSONObject object = array3.optJSONObject(i);

                    Accident life = new Accident();
                    life.id = object.optString("id");
                    life.posttime = object.optString("posttime");
                    life.premium = object.optString("premium");
                    life.pstate = object.optString("pstate");
                    life.insurance_type = object.optString("insurance_type");
                    life.type = object.optString("type");
                    life.ordersn = object.optString("ordersn");

                    d.businessList.add(life);
                }
            }


            info.data = d;

            return info;

        }

        return null;
    }

    public static class Info {
        public Data data;
    }

    public static class Data {
        public List businessList = new ArrayList<>();
    }


    public static class Business {

        //        id": "2",
//                "posttime": "2016-05-28 14:47:03",
//                "total": "5000.00",
//                "pstate": "1",
//                "title": "商业险"
        public String id, posttime, total, pstate, title, type, ordersn;
    }


    public static class Accident {
        public String id, posttime, insurance_type, pstate, premium, type, ordersn;
    }


}
